package com.example.controller;

import com.example.dto.ParamDTO;
import com.example.dto.ResponseDTO;
import com.example.service.TestService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

@RestController
@RequestMapping("/")
public class TestController {

    @Resource
    private TestService testService;

    /**
     * 无参数请求
     * @return
     */
    @RequestMapping("/hello")
    public String hello() {
        return "Hello World!";
    }

    @GetMapping("/test")
    public String test(){
        System.out.println("模拟开始执行业务逻辑...");
        testService.saveDb();
        nested();
        System.out.println("模拟执行业务逻辑结束");
        return "Ok!";
    }

    public static void nested(){
        System.out.println("执行嵌套的内部逻辑");
    }

    public String get() {
        return "hello";
    }

    /**
     * post json请求
     * @param param
     * @return
     */
    @PostMapping("/post")
    public ResponseDTO post(@RequestBody ParamDTO param) {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setName("hai");
        responseDTO.setIds(Arrays.asList("a", "b", "c"));
        return responseDTO;
    }
}
